﻿Imports System.Data.SqlClient

Public Class LoaiTinhTrangDAO

    Public Shared Function GetAllLoaiTinhTrangDAO() As DataTable
        ' Dim sqlcn As SqlDataProvider = New SqlDataProvider()
        Dim cn As SqlConnection
        cn = SqlDataProvider.ConnectionData()
        Dim ds As ArrayList = New ArrayList()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "DanhSach_LoaiTinhTrang"
        cmd.Connection = cn
        Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
        Dim dt As DataTable = New DataTable()
        da.Fill(dt)
        Return dt


    End Function

    Public Shared Function GetMaLoaiTinhTrangDAO() As DataTable
        ' Dim sqlcn As SqlDataProvider = New SqlDataProvider()
        Dim cn As SqlConnection
        cn = SqlDataProvider.ConnectionData()
        Dim ds As ArrayList = New ArrayList()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "DanhSachMa_LoaiTinhTrang"
        cmd.Connection = cn
        Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
        Dim dt As DataTable = New DataTable()
        da.Fill(dt)
        Return dt


    End Function

    Public Shared Sub InsertLoaiTinhTrangDAO(ByVal LoaiTinhTrang As LoaiTinhTrangDTO)
        '  Dim sqlcn As SqlDataProvider = New SqlDataProvider()
        Dim cn As SqlConnection
        cn = SqlDataProvider.ConnectionData()
        Dim ds As ArrayList = New ArrayList()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "Insert_LoaiTinhTrang"
        cmd.Connection = cn
        cmd.Connection.Open()

        Dim para As SqlParameter = New SqlParameter("TenTinhTrang", SqlDbType.NVarChar, 50)
        para.Direction = ParameterDirection.Input
        para.Value = LoaiTinhTrang.TenTinhTrang
        cmd.Parameters.Add(para)


        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

    End Sub

    Public Shared Sub UpdateLoaiTinhTrangDAO(ByVal LoaiTinhTrang As LoaiTinhTrangDTO)
        'Dim sqlcn As SqlDataProvider = New SqlDataProvider()
        Dim cn As SqlConnection
        cn = SqlDataProvider.ConnectionData()
        Dim ds As ArrayList = New ArrayList()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "Update_LoaiTinhTrang"
        cmd.Connection = cn
        cmd.Connection.Open()



        Dim para As SqlParameter = New SqlParameter("MaTinhTrang", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = LoaiTinhTrang.MaTinhTrang
        cmd.Parameters.Add(para)

        para = New SqlParameter("TenTinhTrang", SqlDbType.NVarChar, 50)
        para.Direction = ParameterDirection.Input
        para.Value = LoaiTinhTrang.TenTinhTrang
        cmd.Parameters.Add(para)
      

        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

    End Sub


    Public Shared Sub DeleteLoaiTinhTrangDAO(ByVal MaLoaiTinhTrang As Integer)
        '   Dim sqlcn As SqlDataProvider = New SqlDataProvider()
        Dim cn As SqlConnection
        cn = SqlDataProvider.ConnectionData()
        Dim ds As ArrayList = New ArrayList()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "Delete_LoaiTinhTrang"
        cmd.Connection = cn
        cmd.Connection.Open()

        Dim para As SqlParameter = New SqlParameter("MaTinhTrang", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = MaLoaiTinhTrang
        cmd.Parameters.Add(para)



        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

    End Sub
End Class
